import { Component, OnInit } from '@angular/core';
import {Router} from '@angular/router';
import {UserInfo} from '../../models/UserInfo';
import {API} from '../../services/API';
import {StorageKey} from '../../Constants';
import {NativeService} from '../../services/native.service';
// import {HttpService} from '../../services/http/http.service';
import {StorageService} from '../../services/storage.service';
import {NavController} from '@ionic/angular';

@Component({
  selector: 'app-page-popover',
  templateUrl: './page-popover.component.html',
  styleUrls: ['./page-popover.component.scss'],
})
export class PagePopoverComponent implements OnInit {

  constructor(
      private router: Router,
      private nativeService: NativeService,
      // private http: HttpService,
      private storage: StorageService,
      private nav: NavController,
  ) { }

  ngOnInit() {}

  async exit() {
    const user: UserInfo = await this.storage.read(StorageKey.PERSON_INFO);
    await this.nativeService.showConfirm('确定退出？', '确定', () => {
      // this.http.get(API.LOGOUT, {}).then((res: any) => {
        user.token = '';
        //   退出登录时清空数据。
        this.storage.logOut();
        this.nav.navigateRoot(['/login']);
      // });
    }, '取消', () => {
    });
  }

  change() {
    this.router.navigate(['/change-password'])
  }
}
